<?php
/*
 * program:	均源
 * author:	雨中漫步 & 上善若水 & qhxin
 * email:	qhxin@qhxin.com
 * date:	2014/11/11
 * description:	又是一年双十一，不能剁手，就写点东西吧~~~~~~
 */

defined('IN_SCHOOL') or die();

/*{TranslateTagBegin}*/
class model_memkv extends base_model{

	//hook mod_memkv_start.php
	private $table;

	function __construct() {
		//hook mod_memkv_init_init_before.php
		parent::__construct();
		$this->table = 'memkv';
		//hook mod_memkv_init_init_end.php
	}
	
	//带有过期时间的get
	public function get($key) {
		//hook mod_memkv_get.php
		$key = str_replace('-','',$key);
		$arr = $this->db->get($this->table."-k-$key");
		return !empty($arr) ? core::json_decode($arr['v']) : FALSE;
	}
	
	//带有过期时间的set
	public function set($key, $value) {
		//hook mod_memkv_set.php
		$key = str_replace('-','',$key);
		$value = core::json_encode($value);
		$arr = array();
		$arr['k'] = $key;
		$arr['v'] = $value;
		return $this->db->set($this->table."-k-$key", $arr);
	}
	
	//删除
	public function delete($key) {
		//hook mod_memkv_delete.php
		$key = str_replace('-','',$key);
		return $this->db->delete($this->table."-k-$key");
	}
	
	//hook mod_memkv_end.php
}
/*{TranslateTagEnd}*/

?>